package com.itheima.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.pojo.Orders;
import com.itheima.service.OrdersDetailService;
import com.itheima.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/orderDetail")
public class OrderDetailController {

    @Autowired
    private OrdersDetailService ordersDetailService;

    @Autowired
    private OrdersService ordersService;

    // 后台端:订单明细查询
    @GetMapping("/page")
    public R<Page> page(int page, int pageSize){
        //1 创建分页构造器
        Page<Orders> ordersPage = new Page<>(page,pageSize);
        //2 创建条件构造器 -> 查询所有的订单表信息
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        //3 添加排序条件
        queryWrapper.orderByDesc(Orders::getOrderTime);
        //4 调用方法执行查询
        ordersService.page(ordersPage,queryWrapper);
        //5 返回执行结果
        return R.success(ordersPage);
    }

    // 后台端:根据订单号查询订单

}
